maven
在$HOME\.m2\setting.xml
中配置
mirror
可以使用国内的aliyun mirror,提高下载速度
<mirror>
<id>aliyun</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>jboss</id>
<mirrorOf>central</mirrorOf>
<name>JBoss Public Repository Group</name>
<url>http://repository.jboss.org/nexus/content/groups/public</url>
</mirror>
maven 使用代理服务
maven默认不使用代理服务器,在通过代理服务器访问网络的情况下无法连接到central仓库。
<proxy>
<id>group</id>
<active>true</active>
<protocol>http</protocol>
<username></username>
<password></password>
<host>proxy.corp.com</host>
<port>80</port>
<nonProxyHosts>localhost</nonProxyHosts>
</proxy>
导入Oracle JDBC Driver
由于需要Oracle官方授权,所以maven上无法下载ojdbc,需要自己下载,然后通过命令加载到本地maven库中
C:\apache-maven-3.3.9\bin\mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc6 -Dversion=11.2.4.0.0 -Dpackaging=jar -Dfile=D:\搜狗高速下载\ojdbc6.jar
添加依赖关系
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.4.0.0</version>
</dependency>
JDBC 配置
spring.datasource.url=jdbc:oracle:thin:@192.168.100.1:1521:test
spring.datasource.username=test
spring.datasource.password=test
spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
maven properties
设置源代码文本文件字符集
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.resources.sourceEncoding>UTF-8</project.resources.sourceEncoding>
<spring.version>4.3.12.RELEASE</spring.version>
</properties>
maven plugin
compile plugin
设置Java编译之后的class文件版本
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
dependency plugin
把依赖的lib复制到某个目录下
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>target/classes/lib</outputDirectory>
<outputDirectory>target/job/lib</outputDirectory>
<overWriteIfNewer>true</overWriteIfNewer>
<excludeGroupIds>
junit,org.hamcrest,org.mockito,org.powermock,${project.groupId},com.linkedin.azkaban
</excludeGroupIds>
</configuration>
</execution>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
<configuration>
<verbose>true</verbose>
<detail>true</detail>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</plugin>
resources plugin
把资源文件复制到某个目录下
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/job</outputDirectory>
<resources>
<resource>
<directory>job</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
assembly plugin
打包成zip文件
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/zip.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- append to the packaging phase. -->
<goals>
<goal>single</goal> <!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>
zip.xml
fileSet->directory 需要打包文件所在的目录
fileSet->outputDirectory 相对压缩文件根目录的路径
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>job</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}/job</directory>
<outputDirectory>job</outputDirectory>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>job/lib</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>
</assembly>
book
推荐 《maven 实战》
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。